4270e4efFg3wHCCxXpA0h6yoMTkeSQ tools/python/xen/util/blkif.py
4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/python/xen/util/console_client.py
40c9c468IienauFHQ_xJIcqnPJ8giQ tools/python/xen/util/ip.py
+42a4a80aiq_AT5whiSw-fKhNhRKITw tools/python/xen/util/mac.py
41dde8b0yuJX-S79w4xJKxBQ-Mhp1A tools/python/xen/util/memmap.py
4288c6fcB1kUAqX0gzU85GGxmamS4Q tools/python/xen/util/process.py
4059c6a0pnxhG8hwSOivXybbGOwuXw tools/python/xen/util/tempfile.py
--- /dev/null
+
+from string import join, split
+
+def macToString(mac):
+ return ':'.join(map(lambda x: "%02x" % x, mac))
+
+def macFromString(str):
+ mac = [ int(x, 16) for x in str.split(':') ]
+ if len(mac) != 6:
+ raise ValueError("invalid mac: %s" % str)
+ return mac
import random
+from xen.util.mac import macFromString, macToString
+
from xen.xend import sxp
from xen.xend import Vifctl
from xen.xend.XendError import XendError, VmError
def _get_config_mac(self, config):
vmac = sxp.child_value(config, 'mac')
if not vmac: return None
- mac = [ int(x, 16) for x in vmac.split(':') ]
- if len(mac) != 6: raise XendError("invalid mac: %s" % vmac)
+ try:
+ mac = macFromString(vmac)
+ except:
+ raise XendError("invalid mac: %s" % vmac)
return mac
def _get_config_be_mac(self, config):
vmac = sxp.child_value(config, 'be_mac')
if not vmac: return None
- mac = [ int(x, 16) for x in vmac.split(':') ]
- if len(mac) != 6: raise XendError("invalid backend mac: %s" % vmac)
+ try:
+ mac = macFromString(vmac)
+ except:
+ raise XendError("invalid backend mac: %s" % vmac)
return mac
def _get_config_ipaddr(self, config):
def get_mac(self):
"""Get the MAC address as a string.
"""
- return ':'.join(map(lambda x: "%02x" % x, self.mac))
+ return macToString(self.mac)
def get_be_mac(self):
"""Get the backend MAC address as a string.
"""
- return ':'.join(map(lambda x: "%02x" % x, self.be_mac))
+ return macToString(self.be_mac)
def vifctl_params(self, vmname=None):
"""Get the parameters to pass to vifctl.